package com.sky.controller.admin;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.*;

/**
 * @author liudo
 * @version 1.0
 * @project sky-take-out
 * @date 2024/2/20 15:34:05
 */
@RestController
@RequestMapping("/admin/shop")
@RequiredArgsConstructor
@Slf4j
@Api(tags = "店铺控制器")
public class ShopController {

    private final RedisTemplate<String, Object> redisTemplate;

    /**
     * 设置店铺营业状态
     *
     * @param status 地位
     * @return {@link Result}<{@link ?}>
     */
    @PutMapping("/{status}")
    public Result<?> updateStatus(@PathVariable Integer status) {
        ValueOperations<String, Object> valueOperations = redisTemplate.opsForValue();
        valueOperations.set("ADMIN:SHOP_STATUS", status);
        return Result.success();
    }

    /**
     * 查询状态
     *
     * @return {@link Result}<{@link Integer}>
     */
    @GetMapping("/status")
    public Result<Integer> queryStatus() {
        ValueOperations<String, Object> valueOperations = redisTemplate.opsForValue();
        Integer status = (Integer) valueOperations.get("ADMIN:SHOP_STATUS");
        return Result.success(status == null ? 0 : status);
    }
}
